from proxypool.storages import StorageClient
from proxypool.settings import API_HOST, API_PORT, API_THREADED, IS_DEV
from fastapi import Depends, FastAPI
import uvicorn

app = FastAPI(prefix='/proxy', title=['代理'], responses={404: {"description": "你稳咩乜"}})

def get_conn():
    return StorageClient()

@app.get('/')
async def index():
    return '<h1>少年，想要获取力量吗</h1>'

@app.get('/random')
async def get_proxy(sc:StorageClient = Depends(get_conn)):
    """
    获取随机代理
    """
    return sc.random().string()

@app.get('/all')
async def get_proxy_all(sc:StorageClient = Depends(get_conn)):
    """
    获取全部代理
    """
    return sc.all()


@app.get('/count')
async def get_count(sc:StorageClient = Depends(get_conn)):
    """
    获取数量
    """
    return str(sc.count())

if __name__ == '__main__':
    uvicorn.run('run:app',host=API_HOST, port=API_PORT, reload=True, debug=True, workers=1)